window.attendanceAPI = {
    // 获取考勤记录列表
    getAttendances: async (params = {}) => {
        try {
            const response = await apiClient.get('/api/attendances/', { params });
            return response;
        } catch (error) {
            console.error('获取考勤记录失败:', error);
            throw error;
        }
    },


    // 员工上班打卡
    checkIn: async () => {
        try {
            // 根据当前时间判断考勤状态
            const now = new Date();
            const hour = now.getHours();
            const minute = now.getMinutes();
            const timeInMinutes = hour * 60 + minute;
            
            // 9:30之前算正常，9:30之后算迟到
            const normalTime = 9 * 60 + 30; // 9:30
            const status = timeInMinutes <= normalTime ? 'present' : 'late';
            
            const response = await apiClient.post('/api/attendances/check-in', { status });
            return response;
        } catch (error) {
            console.error('上班打卡失败:', error);
            throw error;
        }
    },

    // 员工下班打卡
    checkOut: async () => {
        try {
            // 根据当前时间判断考勤状态
            const now = new Date();
            const hour = now.getHours();
            const minute = now.getMinutes();
            const timeInMinutes = hour * 60 + minute;
            
            // 18:00之后算正常，18:00之前算早退
            const normalTime = 18 * 60; // 18:00
            const status = timeInMinutes >= normalTime ? 'present' : 'early_leave';
            
            const response = await apiClient.post('/api/attendances/check-out', { status });
            return response;
        } catch (error) {
            console.error('下班打卡失败:', error);
            throw error;
        }
    },

};

